import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description: leetcode.中等题.轮转数组
 */

class Solution {
    public void rotate(int[] nums, int k) {
        k %= nums.length;
        int j = 0;
        for(int i = 0; i < nums.length / 2; i++) {
            int temp = nums[i];
            nums[i] = nums[nums.length - i - 1];
            nums[nums.length - i - 1] = temp;
        }
        for(int i = 0; i < k / 2; i++) {
            int temp = nums[i];
            nums[i] = nums[k - i - 1];
            nums[k - i - 1] = temp;
        }
        for(int i = k; i < k + (nums.length - k) / 2; i++) {
            int temp = nums[i];
            nums[i] = nums[nums.length - j - 1];
            nums[nums.length - j - 1] = temp;
            j++;
        }
        System.out.println(Arrays.toString(nums));
    }


}

public class Test {
    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,4,5,6,7};
        Solution solution = new Solution();
        solution.rotate(nums,3);
    }
}
